import os

from flask import Flask, make_response
import net
import threading

app = Flask(__name__)


@app.route('/')
def hello_world():  # put application's code here
    info = net.getinfo()
    info['memlist'] = net.sqlexec('SELECT * FROM mem ORDER BY id DESC LIMIT 30 ', True)
    info['netlist'] = net.sqlexec('SELECT * FROM net ORDER BY id DESC LIMIT 30 ', True)
    return info


f = open('app.pid', 'w')
f.write(str(os.getpid()))
f.close()
if __name__ == '__main__':
    netThread = threading.Thread(target=net.start)
    netThread.start()
    app.run(host='0.0.0.0', port=54000)
else:
    netThread = threading.Thread(target=net.start)
    netThread.start()
